package com.bilibili.server.controller;

import com.bilibili.model.vo.NearUserVo;
import com.bilibili.model.vo.PageResult;
import com.bilibili.model.vo.RecommendUserQueryParam;
import com.bilibili.model.vo.TodayBest;
import com.bilibili.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author HuangRongFu
 * 2021/11/19 星期五8:32 下午
 */

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;

    /**
     * 今日佳人
     *
     * @Return: ResponseEntity
     */
    @RequestMapping("/todayBest")
    public ResponseEntity todayBest() {

        TodayBest todayBest = tanhuaService.todayBest();

        return ResponseEntity.ok(todayBest);
    }

    /**
     * 每日推荐
     *
     * @param: queryParam
     * @Return: ResponseEntity
     */
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserQueryParam queryParam) {

        PageResult<TodayBest> pageResult = tanhuaService.recommendation(queryParam);

        return ResponseEntity.ok(pageResult);
    }

    /**
     * 佳人信息
     *
     * @param: id
     * @Return: ResponseEntity
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable(value = "id") Long userId) {

        TodayBest todayBest = tanhuaService.findPersonalInfo(userId);

        return ResponseEntity.ok(todayBest);
    }

    /**
     * 查看陌生人消息
     *
     * @param: userId
     * @Return: ResponseEntity
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(@RequestParam("userId") Long userId) {

        String question = tanhuaService.strangerQuestions(userId);

        return ResponseEntity.ok(question);
    }

    /**
     * 回复陌生人消息
     *
     * @param: userId
     * @Return: ResponseEntity
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity replyQuestions(@RequestBody Map<String, Object> paramMap) {

        tanhuaService.replyQuestions(paramMap);

        return ResponseEntity.ok(null);
    }

    /**
     * 推荐列表
     *
     * @param:
     * @Return: ResponseEntity
     */
    @GetMapping("/cards")
    public ResponseEntity queryCardsList() {

        List<TodayBest> list = tanhuaService.queryCardsList();

        return ResponseEntity.ok(list);
    }

    /**
     * 右滑喜欢
     *
     * @param: userId
     * @Return: ResponseEntity
     */
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable(value = "id") Long userId) {

        tanhuaService.love(userId, true);

        return ResponseEntity.ok(null);
    }

    /**
     * 左滑不喜欢
     *
     * @param: userId
     * @Return: ResponseEntity
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable(value = "id") Long userId) {

        tanhuaService.love(userId, false);

        return ResponseEntity.ok(null);
    }


    /**
     * 查附近
     * @param gender
     * @param distance
     * @Return: ResponseEntity
     */
    @GetMapping("/search")
    public ResponseEntity searchNearBy(String gender, Long distance){

        List<NearUserVo> list = tanhuaService.searchNearBy(gender, distance);

        return ResponseEntity.ok(list);
    }

}
